# -*- coding: utf-8 -*-

"""
上传大文件

方法：

"""

import os
import pycurl
from settings import URL, BIG_FILE_PATH


class FileReader:
    def __init__(self, fp):
        self.fp = fp
    def read_callback(self, size):
        return self.fp.read(size)


c = pycurl.Curl()
c.setopt(pycurl.URL, url)
c.setopt(pycurl.UPLOAD, 1)
c.setopt(pycurl.READFUNCTION, FileReader(open(BIG_FILE_PATH, 'rb')).read_callback)
filesize = os.path.getsize(BIG_FILE_PATH)
c.setopt(pycurl.INFILESIZE, filesize)
c.perform()
c.close()
